﻿/*-------------------------------------------------------------------------------------
 * Project Name             : Gems
 * Created By               : Santhini
 * Created Date             : 30 Oct 2012
 * Page Function            : 
 * -------------------------------------------------------------------------------------

*/

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
public partial class CategoryMaster : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["CategoryType_Id"] != null)
            {

                String id = Convert.ToString(Request.QueryString["CategoryType_Id"]);
                Int64 ID = Convert.ToInt64(id);
                ViewState["id"] = ID;
                DisplayRecords();

            }
            LoadGrid();
        }
    }


     #region User Defined Function
    public void SaveRecord()
    {
        try
        {
            Hashtable hstbl1 = new Hashtable();
            hstbl1.Add("TypeCode", txtCattypecode.Text);
            hstbl1.Add("TypeName", txtcatname.Text);
            if (ViewState["id"] != null)
            {
                hstbl1.Add("@CategoryType_Id", Convert.ToInt32(ViewState["id"]));
            }

            Int64 intIdentity = DataAccessLayer.ExecuteCommand_RowsAffected("GemsCategoryTypeMaster_InsertUpdate_SP", hstbl1);

            if (intIdentity > 0)
            {
                LoadGrid();
                JSAlert.Show("Insert The Record ");

            }
            else
            {
                JSAlert.Show("Insert Failed");
            }
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }



        }
    void LoadGrid()
    {

        try
        {
            Hashtable hstbl = new Hashtable();
            DataSet ds = DataAccessLayer.GetDataset("GemsCategoryTypeMaster_Fetch_SP", hstbl);

            GridView1.DataSource = ds;
            GridView1.DataBind();

        }



        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }


    }
    private void DisplayRecords()
    {
        try
        {

            Hashtable hstbl = new Hashtable();
            hstbl.Add("@CategoryType_Id", Convert.ToInt32(ViewState["id"]));
            DataSet ds = DataAccessLayer.GetDataset("GemsCategoryTypeMaster_Fetch_SP", hstbl);

            if (ds.Tables[0].Rows.Count > 0)
            {

                txtCattypecode.Text = ds.Tables[0].Rows[0]["TypeCode"].ToString();
                txtcatname.Text = ds.Tables[0].Rows[0]["TypeName"].ToString();


            }
        }

        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }
     #endregion
    #region Button Event
    protected void ibtdelete_Click(object sender, EventArgs e)
    {
        try
        {
            GridViewRow gvr = (GridViewRow)(sender as Control).Parent.Parent;
            int ID = Convert.ToInt32(GridView1.DataKeys[gvr.RowIndex].Values["CategoryType_Id"].ToString());
            Hashtable hstbl = new Hashtable();
            hstbl.Add("@CategoryType_Id", ID);
            Int64 var = DataAccessLayer.ExecuteCommand_RowsAffected("GemsCategoryTypeMaster_Delete_SP", hstbl);
            LoadGrid();
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }

    }
    protected void ibtEdit_Click(object sender, EventArgs e)
    {
        try
        {
            GridViewRow gvr = (GridViewRow)(sender as Control).Parent.Parent;
            int ID = Convert.ToInt32(GridView1.DataKeys[gvr.RowIndex].Values["CategoryType_Id"].ToString());

            Response.Redirect("~/Master/CategoryTypeMaster.aspx?CategoryType_Id=" + ID, true);
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }


    protected void lnkmapp_Click(object sender, EventArgs e)
    {

        try
        {
            GridViewRow gvr = (GridViewRow)(sender as Control).Parent.Parent;
            int ID = Convert.ToInt32(GridView1.DataKeys[gvr.RowIndex].Values["CategoryType_Id"].ToString());

            Response.Redirect("~/Master/CategoryMapping.aspx?CategoryType_Id=" + ID, true);
        }
        catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
    }
 

    

    protected void btn_add_Click(object sender, EventArgs e)
    {
        try
        {
        SaveRecord();
        }
         catch (Exception ex)
        {
            JSAlert.Show(ex.Message);
        }
}

 
    }
    #endregion





